﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Sunimage.Spjg.Common;
using Sunimage.Spjg.DAL;

namespace Sunimage.Spjg.BLL
{
    public class FileBl
    {
        //得到用户存放文件的地址
        public string GetFileDirectory(string path, int userId)
        {
            //存放规律： Web/File/WebDisk/userId/filename.ext
            return string.Format("{0}\\File\\WebDisk\\{1}\\", path, userId);
        }

        public void Create(DiskFile file)
        {
            file.Id = Guid.NewGuid();
            FileDa.Insert(file);
        }

        public List<DiskFile> GetAll()
        {
            return FileDa.GetAll();
        }

        public List<DiskFile> GetAllPulbicFile()
        {
            return FileDa.GetAll().FindAll(f => f.IsShared);
        }

        public List<DiskFile> GetAll(int userId)
        {
            return FileDa.GetAll().FindAll(f => f.OwnerId == userId);
        }

        public void Delete(Guid id)
        {
            FileDa.Delete(id);
        }

        public DiskFile GetById(Guid id)
        {
            return FileDa.GetAll().Find(f => f.Id == id);
        }

        public void Update(DiskFile file)
        {
            FileDa.Update(file);
        }

        public int GetTotalCount()
        {
            return FileDa.GetAll().Count;
        }
    }
}
